package com.dc.kylin.nettychart.chat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class NettyListener implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    private WebSocketNettyServer server;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {

        if(event.getApplicationContext().getParent() == null){
            try {
                server.start();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
}
